import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const routes = [
  {
    path: '/',
    name: '登录',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/login',
    name: '登录',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../layout/HomePage.vue'),
    redirect: "/home/firstPage",
    children:[
      {path: 'firstPage', name: '首页',component: () => import('../views/HomeView.vue')},
      {path: 'userM', name: '用户管理',component: () => import('../views/UserM.vue')},
      {path: 'roleM', name: '角色管理',component: () => import('../views/RoleM.vue')},
      {path: 'menuM', name: '菜单管理',component: () => import('../views/MenuM.vue')},
      {path: 'permissionM', name: '权限管理',component: () => import('../views/PermissionM.vue')},
      {path: 'mine', name: '个人中心',component: () => import('../views/Mine.vue')},
      {path: 'cxcyxm', name: '项目查询',component: () => import('../views/cxcyxm/XmQuery.vue')},
      {path: 'cxcyxmXq', name: '项目详情',component: () => import('../views/cxcyxm/XmDetail.vue')},
      {path: 'cxcyxmSb', name: '项目申报',component: () => import('../views/cxcyxm/XmShengbao.vue')},
      {path: 'xmJdjl', name: '进度管理',component: () => import('../views/cxcyxm/XmJdjl.vue')},
      {path: 'xmqk', name: '项目一览',component: () => import('../views/cxcyxm/Xmhjqk.vue')},
      {path: 'xmcxsq', name: '撤销申请',component: () => import('../views/cxcyxm/XmCxsq.vue')},
      {path: 'xmkj', name: '项目空间查询',component: () => import('../views/xmkj/XmkjQuery.vue')},
      {path: 'xmkjDsjl', name: '空间卫生检查',component: () => import('../views/xmkj/Xmdsjl.vue')},
      {path: 'xmkjSq', name: '项目空间申请',component: () => import('../views/xmkj/XmkjSq.vue')},
      {path: 'xmhjjl', name: '项目获奖记录',component: () => import('../views/cxcyxm/Xmhjjl.vue')},
    ]
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  let token = localStorage.getItem("token")
  if(token!=null || to.path=='/'){
    next()
  }else{
    next('/')
  }
})


export default router
